package hashset;

import domain.Student;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class CollectionsDemo1 {
    public static void main(String[] args) {
        ArrayList<String> list=new ArrayList<>();
//        ArrayList不会去重
        Collections.addAll(list,"a","c","c","b","d");
        System.out.println(list);
//        重写打乱顺序
        Collections.shuffle(list);
        System.out.println(list);

        ArrayList<Integer> nums=new ArrayList<>();
        Collections.addAll(nums,11,22,33,44,42,15,16);
        System.out.println(nums);
        System.out.println(Collections.max(nums));
        System.out.println(Collections.min(nums));

        ArrayList<Student> stu=new ArrayList<>();
        Collections.addAll(stu,new Student("zhangsan",23),new Student("lisi",22),new Student("lose",20),new Student("lisa",20));
        System.out.println(stu);
        System.out.println("学生的年龄最大的对象是："+Collections.max(stu));
        System.out.println("学生的年龄最小的对象是："+Collections.min(stu));
//        stu里面的0和2位置的两个元素交换位置
        Collections.swap(stu,0,2);
        System.out.println(stu);
        //sort排序

        ArrayList<Integer> box=new ArrayList<>();
        Collections.addAll(box,1,2,3,4,5);
        System.out.println(box);
        System.out.println("box1号索引位置的元素:"+box.get(1));
//        重载方法降序排序
        Collections.sort(box, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });
        System.out.println(box);

    }
}
